//
//  LLLabelListCell.m
//  LLLabel
//
//  Created by LQ on 2020/12/9.
//

#import "WKLabelListCell.h"

@implementation WKLabelListModel

- (Class)cell {
    return WKLabelListCell.class;
}

- (NSNumber *)showArrow {
    return @(false);
}

@end

@interface WKLabelListCell ()

@property(nonatomic,strong) UILabel *titleLbl;
@property(nonatomic,strong) UILabel *descLbl;
@property(nonatomic,strong) WKLabelListModel *model;

@end

@implementation WKLabelListCell

+ (CGSize)sizeForModel:(WKFormItemModel *)model {
    return CGSizeMake(WKScreenWidth, 70.0f);
}

- (void)setupUI {
    [super setupUI];
    [self.contentView addSubview:self.titleLbl];
    [self.contentView addSubview:self.descLbl];
}

- (void)refresh:(WKLabelListModel *)model {
    [super refresh:model];
    self.model = model;
    self.titleLbl.text = [NSString stringWithFormat:@"%@（%d）",model.title?:@"",model.num.intValue];
    [self.titleLbl sizeToFit];
    self.descLbl.hidden = YES;
    if(model.desc && ![model.desc isEqualToString:@""]) {
        self.descLbl.hidden = NO;
        self.descLbl.text = model.desc;
        [self.descLbl sizeToFit];
    }
    
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    self.titleLbl.lim_centerY_parent = self.contentView;
    self.titleLbl.lim_left = 15.0f;
    self.titleLbl.lim_width = self.contentView.lim_width - self.titleLbl.lim_left*2.0f;
    if(!self.descLbl.hidden) {
        CGFloat descTopSpace = 2.0f;
        self.titleLbl.lim_top =  self.contentView.lim_height/2.0f - (self.titleLbl.lim_height + self.descLbl.lim_height + descTopSpace)/2.0f;
        
        self.descLbl.lim_top = descTopSpace + self.titleLbl.lim_bottom;
        self.descLbl.lim_left = self.titleLbl.lim_left;
        self.descLbl.lim_width = self.contentView.lim_width - self.titleLbl.lim_left*2.0f;
    }
    
    
    
}

- (UILabel *)titleLbl {
    if(!_titleLbl) {
        _titleLbl = [[UILabel alloc] init];
        _titleLbl.font = [[WKApp shared].config appFontOfSize:16.0f];
        _titleLbl.textColor = [WKApp shared].config.defaultTextColor;
        _titleLbl.numberOfLines = 1;
        _titleLbl.lineBreakMode = NSLineBreakByTruncatingMiddle;
    }
    return _titleLbl;
}

- (UILabel *)descLbl {
    if(!_descLbl) {
        _descLbl = [[UILabel alloc] init];
        _descLbl.font = [[WKApp shared].config appFontOfSize:16.0f];
        _descLbl.textColor =[WKApp shared].config.tipColor;
        _descLbl.numberOfLines = 1;
        _descLbl.lineBreakMode = NSLineBreakByTruncatingTail;
    }
    return _descLbl;
}

@end
